package team.helpmephone.app.ring;

import team.helpmephone.app.R;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ActivityRingtone extends Activity {
	private static final String TAG = "ACTIVITY RINGTONE";
	Button btnStop;
	MediaPlayer media;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ringtone_layout);

		Log.v(TAG, "On Create");

		initialize();
	}

	private void initialize() {
		Log.v(TAG, "Ringtone Initialize...");
		executeBell();
		btnStop = (Button) findViewById(R.id.btnStop);
		btnStop.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				if (media.isPlaying()) {
					media.stop();
				}
			}
		});
	}

	private void executeBell() {
		Log.v(TAG, "Ringtone Start...");
		media = MediaPlayer.create(getApplicationContext(), R.raw.oh);
		media.start();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		if (media != null) {
			media = null;
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}
}
